<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ProjectInvoice extends Model
{
    use HasFactory;

    protected $fillable = [
        'project_id','user_id','price','tax_rate','mix',
        'name','tax_id','address','mobile','bank','bank_number','bank_account','email','postal_code',
        'b_name','b_tax_id','b_address','b_mobile','b_bank','b_bank_number','b_bank_account','b_email','b_postal_code',
        'invoice_amount','invoice_type','invoice_content','remarks','tax_price'
    ];

    const POSTONLY = [
        'project_id','user_id','price','tax_rate','mix',
        'name','tax_id','address','mobile','bank','bank_number','bank_account','email','postal_code',
        'b_name','b_tax_id','b_address','b_mobile','b_bank','b_bank_number','b_bank_account','b_email','b_postal_code',
        'invoice_amount','invoice_type','invoice_content','remarks','tax_price'
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function project()
    {
        return $this->hasOne(Project::class,'id','project_id')->select('id','title','status','price','address');
    }

    public function application()
    {
        return $this->hasOne(Application::class,'source_id','id')->where('model','ProjectInvoice')->orderBy('id','desc');
    }
}
